package com.bruce.codeFactory.Thread;

/**
 * @author luotuan
 * @Description
 * @create 2019-02-18 21:23
 **/
public class TicketWindowsDemo {
    public static void main(String[] args) {
        final TicketWindows ticketWindows = new TicketWindows();
        Thread t1 = new Thread(ticketWindows, "窗口1");
        Thread t2 = new Thread(ticketWindows, "窗口2");
        Thread t3 = new Thread(ticketWindows, "窗口3");
        t1.start();
        t2.start();
        t3.start();
    }
}

class TicketWindows implements Runnable {
    private static final int MAX = 150;
    private int index = 1;
    private final Object MONITOR = new Object();

    @Override
    public void run() {
        while(true){
            synchronized (MONITOR){
                if(index>MAX){
                    break;
                }
                System.out.println(Thread.currentThread().getName()+" 的号码是："+(index++));
            }
        }
    }
}
